<%@page contentType="text/html; charset=UTF-8"%>
<%@ page import="com.qingneng.security.CurrentUser" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>客户信息</title>
<%@ include file="../../common/common.jsp"%>

<script type="text/javascript">


function formatter(value,row,index){
	if (value==1){
		var s = '住宅';
		return s;
	}
	if (value==2){
		var s = '非住宅';
		return s;
	}
}


var url;
function new_info() {

	$('#dlg').dialog('open').dialog('setTitle', '新增客户');
	
	$('#fm').form('clear');
}

function edit_info() {
	var row = $('#dg').datagrid('getSelected');
	
	
	if (row) {
		$('#dlg').dialog('open').dialog('setTitle', '编辑客户');
	
		$('#fm').form('load', row);
		
	}
}



function save_info() {
	$('#fm').form('submit', {
		url : '<%=basePath %>saveCustomerInfoAction!saveData.do',
		onSubmit : function() {
			return $(this).form('validate');
		},
		success : function(result) {
			var result = eval('(' + result + ')');
			//alert(result);
			if (result.message=='success') {
				$('#dlg').dialog('close'); // close the dialog
				$('#dg').datagrid('reload'); // reload the user data
		} else {
		$.messager.show( {
			title : '错误提示',
			msg : result.message
		});
	}
}
	});
}
function remove_info() {
	var row = $('#dg').datagrid('getSelected');
	if (row) {
		$.messager.confirm('Confirm',
				'请确认是否删除该客户信息?', function(r) {
					if (r) {
						$.post('<%=basePath %>saveCustomerInfoAction!destoryData.do', {
							id : row.id
						}, function(result) {
							if (result.message=='success') {
								$('#dg').datagrid('reload'); // reload the user data
							} else {
								$.messager.show( { // show error message
										title : '错误提示',
										msg : result.message
										});
							}
						}, 'json');
					}
				});
	}
}


// 查询
function search_data(){	
	var ct_name =$("#ct_name").attr('value');
	var d_start = $("#dd1").datebox("getText");
	var d_end= $("#dd2").datebox("getText");
	
	var url = "<%=basePath%>loadCustomerInfoAction!loadData.do?"+
			"customerInfo.customerName="+ct_name+"&customerInfo.query_startTime="+d_start+"&customerInfo.query_endTime="+d_end;
	var params = {} ;
	jQuery.post(url,params,function(data){
		//alert(data);
		$('#dg').datagrid("loadData",data);
	
	},'json');
}

$(document).ready(function(){
	
	$(function(){
		$('#dd1').datebox({
		    formatter: function(date){ return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();},
		    parser: function(date){ return new Date(Date.parse(date.replace(/-/g,"/")));}
		});
		$('#dd2').datebox({
		    formatter: function(date){ return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();},
		    parser: function(date){ return new Date(Date.parse(date.replace(/-/g,"/")));}
		});
	})
	

	/* $("input[type=checkbox][checked]").each(function(){
	 //由于复选框一般选中的是多个,所以可以循环输出 
	 alert($(this).val()); 
	});  */


	
	
})
	function checkEvent(){
		 $("input[name=buildType]").each(function(){
			// alert($(this).attr('checked')); 
			 if($(this).attr('checked')=='checked'){
				 //alert($(this).val());
				 if($(this).val()=='1'){
					$('#zhuzai').show(); 
				 }
 				 if($(this).val()=='2'){
 					$('#jianzhu').show(); 
				 }
			 } else{
				// alert('11:'+$(this).val());
				 if($(this).val()=='1'){
				 $('#zhuzai').hide(); 
				 }
				 if($(this).val()=='2'){
				 	$('#jianzhu').hide(); 
				 }
			 } 
			 
		})
	}
</script>
	</head>
	<body>
	
			<table  width="1100px"  height="20px" style="text-align:center;background:#f3eeaf;border:1px solid #b3dfda">
					<tr>
						<td width="60">日期 :</td>
						<td><input class="easyui-datebox" style="width:100px" id="dd1">至: <input class="easyui-datebox" style="width:100px" id="dd2"></td>
						<td width="60">客户名称: </td>
						<td><input  style="width:150px" id="ct_name" name="ct_name"></td>
						<td><a href="#" class="easyui-linkbutton" plain="true" iconCls="icon-search" onclick="search_data()">查询</a></td>
					</tr>		
			</<table>
		<table id="dg" title="客户信息" class="easyui-datagrid"
			style="width: 1100px; height: 350px" url="<%=basePath %>loadCustomerInfoAction!loadData.do"
			toolbar="#toolbar" pagination="true" rownumbers="true"
			fitColumns="true" singleSelect="true" >
			<thead>
				<tr>
					<th field="customerNo" width="30" align="center">
						客户编号
					</th>
					<th field="customerName" width="50" align="center">
						客户名称
					</th>
					<th field="customerContactPerson" width="40" align="center">
						客户联系人
					</th>
					<th field="customerContactPhone" width="40" align="center">
						客户联系电话
					</th>
					<th field="projectAddress" width="40" align="center" >
						项目地址
					</th>
					<th field="cesspoolNum" width="30" align="center" >
						化粪池数量
					</th>
					
					<th field="pipeLength" width="30" align="center">
						管道长度
					</th>
					
					<th field="cessfamilynum" width="30" align="center">
						住宅户数
					</th>
					<th field="cessarea" width="30" align="center">
						建筑面积
					</th>
					
					<th field="isArrival" width="30" align="center">
						车辆到达
					</th>
					
					<th field="isCondition" width="30" align="center">
						提供水电
					</th>
					
					<th field="buildType" width="30" align="center" formatter="formatter">
						建筑类型
					</th>
					
					<th field="respPerson" width="20" align="center">
						责任人
					</th>
					<th field="respPersonPhone" width="30" align="center">
						责任人电话
					</th>
					
					<th field="remark" width="50" align="center">
						说明
					</th>
				</tr>
			</thead>
		</table>

		<div id="toolbar">
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" 
				onclick="new_info()">新建</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-edit"
				 onclick="edit_info()">编辑</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-remove"
				 onclick="remove_info()">删除</a>
				  
		</div>

		<div id="dlg" class="easyui-dialog"
			style="width: 700px; height: 400px;" closed="true" buttons="#dlg-buttons">
			<div class="ftitle">
				客户信息
			</div>
			<form id="fm" method="post" >
				<table  style="border:1px solid #b3dfda;width:600px">
				
					<tr colspan="2" style="display: none">
						
						<td>
							<div class="fitem">
								<label>
									ID:
								</label>
								<input name="id" class="easyui-validatebox" >
							</div>
						</td>
						
					</tr>
					
					<tr>
						
						<td>
							<div class="fitem">
								<label>
									客户编号:
								</label>
								<input name="customerNo" class="easyui-validatebox" required="true">
							</div>
						</td>
						<td>
							<div class="fitem">
								<label>
									客户名称:
								</label>
								<input name="customerName" class="easyui-validatebox" required="true">
							</div>
						</td>

					</tr>

					<tr>
						<td>
							<div class="fitem">
								<label>
									客户联系人:
								</label>
								<input name="customerContactPerson">
							</div>
						</td>
						<td>
							<div class="fitem">
								<label>
									联系电话:
								</label>
								<input name="customerContactPhone" >
							</div>
						</td>
					</tr>
				

					<tr>
					
						<td colspan="2">
						<div class="fitem">
									<label>
										项目地址:
									</label>
									<input name="projectAddress" size=50>
						</div>
								
	
						</td>
					
					</tr>
					
					
					
					<tr>
					
						
						
						<td >
							<div class="fitem">
										<label>
											化粪池数量:
										</label>
										<input name="cesspoolNum" >个
							</div>
								
	
						</td>
					
						<td >
							<div class="fitem">
										<label>
											化粪池容积:
										</label>
										<input name="cesspoolcap" >
							</div>
								
	
						</td>
					</tr>
					
					<tr>
					
						<td >
						<div class="fitem">
									<label>
										清掏周期:
									</label>
									<input name="cesspoolCleanTime" >
						</div>
								
	
						</td>
					
						<td >
							<div class="fitem">
										<label>
											最后清掏日期:
										</label>
										<input name="lastcleanTime" class="easyui-datebox">
							</div>
								
	
						</td>
					</tr>
					
					
					
					<tr>
					
						<td >
						<div class="fitem">
									<label>
										管道长度:
									</label>
									<input name="pipeLength" >m
						</div>
								
	
						</td>
					
						<td >
							
							
							<div class="fitem">
									<label>
										建筑类型:
									</label>
									
									<input type="checkbox" name="buildType" value="1" onchange="checkEvent()">住宅
									<input type="checkbox" name="buildType" value="2" onchange="checkEvent()">非住宅
							</div>
								
								
	
						</td>
					</tr>
					
					<tr>
					
						<td >
						<div class="fitem">
									<label>
										车辆到达:
									</label>
									<input type="radio" name="isArrival" value="是">是
									<input type="radio" name="isArrival" value="否">否
									
						</div>
								
	
						</td>
					
						<td >
							<div class="fitem">
										<label>
											提供水电:
										</label>
										
										<input type="radio" name="isCondition" value="是">是
										<input type="radio" name="isCondition" value="否">否
							</div>
								
	
						</td>
					</tr>
					
					
					<tr>
					
						<td >
						<div class="fitem">
									<label>
										责任人:
									</label>
									<input name="respPerson" >
						</div>
								
	
						</td>
					
						<td >
							<div class="fitem">
										<label>
											责任人电话:
										</label>
										<input name="respPersonPhone" >
							</div>
								
	
						</td>
					</tr>
					
					
					<tr>
					
						
						<td >
							<div class="fitem"  id="zhuzai" style="display: none">
										<label>
											住宅户数:
										</label>
										<input name="cessfamilynum" >户
							</div>
						</td>	
						<td>
							<div class="fitem"  id="jianzhu" style="display: none">
										<label>
											建筑面积:
										</label>
										<input name="cessarea" >m<sup>2</sup>
							</div>
	
						</td>
					</tr>
					
					<tr>
						<td colspan="2">
						<div class="fitem">
									<label>
										清掏意向:
									</label>
									<input name="cleanremark" size="50"/>
						</div>
						</td>
					</tr>
					
					<tr>
					
						<td colspan="2">
							<div class="fitem">
										<label>
											说明:
										</label>
										<input name="remark" size="50"/>
							</div>
	
						</td>
					</tr>
							

				</table>

			</form>
		</div>
		<div id="dlg-buttons">
			<a href="#" class="easyui-linkbutton" iconCls="icon-ok"
				onclick="save_info()">保存</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-cancel"
				onclick="javascript:$('#dlg').dialog('close')">取消</a>
		</div>
	</body>
</html>